package com.uaroadshow.finale.service.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.annotation.Dao;
import com.uaroadshow.entity.trade.Product;
import com.uaroadshow.entity.user.User;
import com.uaroadshow.entity.user.UserCourse;
import com.uaroadshow.finale.dao.UserCourseDao;
import com.uaroadshow.finale.service.UserCourseService;

/**
 *
 * @author Ark
 *
 */
@Service("userCourseService")
public class UserCourseServiceImpl extends DataServiceImpl<UserCourse> implements UserCourseService {

    @Dao
    private UserCourseDao userCourseDao;
    
    /* (non-Javadoc)
     * @see com.uaroadshow.finale.service.UserCourseService#list(com.uaroadshow.entity.user.User)
     */
    public List<UserCourse> list(User user) {
        return userCourseDao.list(user);
    }
    
    /* (non-Javadoc)
     * @see com.uaroadshow.finale.service.UserCourseService#verificate(com.uaroadshow.entity.user.UserCourse, java.util.List)
     */
    public void verificate(UserCourse userCourse, List<String> codes) {
        
        Product product = userCourse.getProduct();
        if (product.isParent()) {
            
            if (CollectionUtils.size(codes) == 4) {
                genericDaoSupport.update(userCourse.verificate());
            } else {
                String code = StringUtils.join(codes, "|");
                genericDaoSupport.update(userCourse.verificate(false, code));
            }
            
        } else {
            genericDaoSupport.update(userCourse.verificate());
        }
        
    }
    
}
